from manimlib import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        mn=Line(LEFT*6,RIGHT*6).shift(DOWN*2.5)
        m,n,a=mn.get_left(),mn.get_right(),mn.get_center()
        b,c=mn.point_from_proportion(1/3),mn.point_from_proportion(5/6)
        mn_length=mn.get_length()
        arc3=Arc(mn_length/2,0,PI,arc_center=a)
        arc2=Arc(mn_length/3,0,PI,arc_center=b)
        arc1=Arc(mn_length/6,0,PI,arc_center=c)
        bm,cn=Line(b,m),Line(c,n)
        b2,b1=Brace(bm,DOWN),Brace(cn,DOWN)
        self.add(mn,arc3,arc2,arc1,b2,b1,Dot(a),Dot(b),Dot(c),
            Tex('A').next_to(a,DOWN),
            Tex('B').next_to(b,UP),
            Tex('C').next_to(c,UP),
            Tex('2').next_to(b2,DOWN),
            Tex('1').next_to(b1,DOWN)
        )
        #
        d=[2.57,0.93,0]
        circle=Circle(mn_length/7).move_to(d).set_color(LV)
        self.add(circle,Dot(d),
            Tex('D').next_to(d),
            Tex('r=?').next_to(circle,UR).set_color(LV)
        )
        self.wait()

class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        mn=Line(LEFT*6,RIGHT*6).shift(DOWN*2.5)
        m,n,a=mn.get_left(),mn.get_right(),mn.get_center()
        b,c=mn.point_from_proportion(1/3),mn.point_from_proportion(5/6)
        mn_length=mn.get_length()
        arc3=Arc(mn_length/2,0,PI,arc_center=a)
        arc2=Arc(mn_length/3,0,PI,arc_center=b)
        arc1=Arc(mn_length/6,0,PI,arc_center=c)
        bm,cn=Line(b,m),Line(c,n)
        b2,b1=Brace(bm,DOWN),Brace(cn,DOWN)
        self.add(mn,arc3,arc2,arc1,b2,b1,Dot(a),Dot(b),Dot(c),
            Tex('A').next_to(a,DOWN),
            Tex('B').next_to(b,UP),
            Tex('C').next_to(c,UR),
            Tex('2').next_to(b2,DOWN),
            Tex('1').next_to(b1,DOWN)
        )
        #
        d=[2.57,0.93,0]
        circle=Circle(mn_length/7).move_to(d).set_color(LV)
        self.add(circle,Dot(d),
            Tex('D').next_to(d),
        )
        # p2
        e=mn.point_from_proportion(2/3)
        ad,bd,cd=Line(a,d),Line(b,d),Line(c,d)
        line_r=ad.copy().set_length(mn_length/7).next_to(d,UR,buff=0)
        theta=Angle(cd,Line(c,a))
        self.add(ad,bd,cd,line_r,theta,
            Tex('r').move_to([3,1.7,0]),
            Tex(r'\theta').next_to(theta,UL,buff=0),
            Tex('2').move_to([-0.5,-1,0]),
            Tex('1').move_to([3.8,-1.5,0]),
        )
        self.wait()